package complexity.cohesion;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Main {

	
	
	public static void main(String[] args) {
		
		// Traverse Directory
		// Parse source files in directory
		// Calculate Complexity
		// Calculate Cohesion
		// Display result in a report
		 
		String directoryFolder = "C:\\juno\\eclipse\\workspace\\deneme\\testpackagefolders";
		DirectoryTraversal traversal = new DirectoryTraversal();
		
		List<String> files = traversal.getJavaSourceFileList(directoryFolder);
		Set<String> packageNameSet = new HashSet<String>();
		
		for(String f : files)
		{
			BufferedReader br = null;
			String packageName = "";
			
			try {
				String sCurrentLine;
				br = new BufferedReader(new FileReader(f));
				int lineNumber = 0;

				while((sCurrentLine = br.readLine()) !=null)
				{
					++lineNumber;
					if( lineNumber == 1 )
					{
						LineCommentDeleter lineCommentDeleter = new LineCommentDeleter();
						sCurrentLine = lineCommentDeleter.LineCommentCheckerAndDeleter(sCurrentLine);
						System.out.println(sCurrentLine);
						
						PackageParser packageParser = new PackageParser(sCurrentLine);
						packageName = packageParser.getPackageName();
						packageNameSet.add(packageName);
					}
					
					//System.out.println(sCurrentLine);
				}
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		for (String str : packageNameSet) {
			System.out.println(str);
		}
	}

}
